package com.team10.hotel.service.impl;

import com.team10.hotel.domain.Hotel;
import com.team10.hotel.domain.Room;
import com.team10.hotel.domain.RoomExample;
import com.team10.hotel.domain.RoomImage;
import com.team10.hotel.mapper.RoomImageMapper;
import com.team10.hotel.mapper.RoomMapper;
import com.team10.hotel.service.RoomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class RoomServiceImpl implements RoomService {
    @Autowired
    private RoomMapper roomMapper;
    @Autowired
    private RoomImageMapper roomImageMapper;
    @Override
    public List<Room> listRoom(Integer id) {
        return roomMapper.selectRoomByHotelId(id);
    }

    @Override
    public int insertRoom(Room room) {
        return roomMapper.insert(room);
    }

    @Override
    public int deleteRoomByPrimaryKey(Integer id) {
        List<RoomImage>roomImages=roomImageMapper.selectRoomImageByRoomId(id);
        for (RoomImage roomImage:roomImages
             ) {
            roomImageMapper.deleteByPrimaryKey(roomImage.getImageId());
        }
        return roomMapper.deleteByPrimaryKey(id);
    }

    @Override
    public Room findRoomByPrimaryKey(Integer id) {
        return roomMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateRoom(Room room) {
        return roomMapper.updateRoom(room);
    }

    @Override
    public int selectLastInsertId() {
        return roomMapper.selectLastInsertId();
    }

    @Override
    public List<Room> roomAndImage(int id) {
        return roomMapper.selectRoomAndImage(id);
    }


}
